﻿using System;
using System.Timers;

namespace CSharpConsoleTestSolution.Demo {
    /**
     * 本节内容
     * 初步了解事件
     * 事件的应用
     * 深入理解事件
     * 事件的声明
     * 问题辨析
     */
    public class P21_Event {

        /**
         * 1.Timber 事件, 时间: 17:40
         */
        public static void timer_event() {
            Console.WriteLine("1.Timber 事件");
            Console.WriteLine("var timer = new Timer();");
            Console.WriteLine("var boy = new Boy();");
            Console.WriteLine("timer.Interval = 1000;");
            Console.WriteLine("timer.Elapsed += boy.Action;");
            Console.WriteLine("timer.Start();");
            Console.WriteLine("Console.ReadLine();  //一直等待");
            var timer = new Timer();
            var boy = new Boy();
            timer.Interval = 1000;
            timer.Elapsed += boy.Action;
            timer.Start();
            Console.ReadLine();
            
            Console.WriteLine("更多事件见: MainWindow.xaml.cs");
        }
        
        private class Boy {
            public void Action(object sender, ElapsedEventArgs e) {
                Console.WriteLine($"sender={sender}, e.SignalTime={e.SignalTime}");
            }
        }
    }
}